package top.vanchor.myblog2back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import top.vanchor.myblog2back.entity.ExtraBloodSugar;
import top.vanchor.myblog2back.mapper.ExtraBloodSugarMapper;
import top.vanchor.myblog2back.service.IExtraBloodSugarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ding
 * @since 2022-04-06
 */
@Service
public class ExtraBloodSugarServiceImpl extends ServiceImpl<ExtraBloodSugarMapper, ExtraBloodSugar> implements IExtraBloodSugarService {

    @Resource
    private ExtraBloodSugarMapper mapper;

    @Override
    public PageInfo<ExtraBloodSugar> getList(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        QueryWrapper<ExtraBloodSugar> queryWrapper = new QueryWrapper<>();
        //倒序查询
        queryWrapper.orderByDesc("blood_id");
        return new PageInfo<>(mapper.selectList(queryWrapper));
    }

    @Override
    public int updateItem(ExtraBloodSugar bloodSugar) {
        QueryWrapper<ExtraBloodSugar> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("blood_id", bloodSugar.getBloodId());
        return mapper.update(bloodSugar, queryWrapper);
    }

    @Override
    public int add(ExtraBloodSugar bloodSugar) {
        try {
            return mapper.insert(bloodSugar);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
    }
}
